#include<stdio.h>
#include<string.h>
#include "uart.h"
#include <unistd.h>

char jiaoyan( unsigned char * da ,int len)
{
	da[len - 1 ] = da[2];
	for( int i = 3 ; i < len -1 ; i ++ )
	{
		da[ len - 1 ] ^=da[i];
	}
}

char write_car_id(char * car_id)
{
	int car_len = strlen(car_id);
	char send_da[20]={0xAA,0xAB,0x0C,0x12,0x00,0x00,0x00,0x06,0x31,0x31,0x31,0x31,0x31,0x31,0x11};
	send_da[2] = 6 + car_len;
	send_da[7] = car_len;
	for( int i = 0; i < car_len ; i ++ )
	{
		send_da[8+i] = car_id[i];
	}
	jiaoyan(send_da,send_da[2]+3);
	write(uart,send_da,send_da[2]+3);
}

void get_car_id(char * da,char * car_id,int len)
{
	for( int i = 0 ; i < len ; i ++ )
	{
		car_id[i] = da[i];
	}
}

